package com.opencart.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.opencart.domain.Category;
import com.opencart.service.CategoryService;
import com.opencart.utils.web.pagination.PagedResultSet;
import com.opencart.utils.web.pagination.Pager;

@Controller
@RequestMapping("/home")
public class HomeController {
	@Autowired
	private CategoryService categoryService;

	public CategoryService getCategoryService() {
		return categoryService;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	@RequestMapping(value = "/{name}", method = RequestMethod.GET)
	public String getMovie(@PathVariable String name, ModelMap model,
			Pager pager) {
		Category category = this.getCategoryService().findById(1L);
		Category c = new Category();
		c.setName("b");
		c.setDescription("b");
		c.setParent(category);
		this.getCategoryService().saveOrUpdate(c);
		System.out.println("childern:" + category.getChildren().size());

		PagedResultSet pr = this.getCategoryService().paginate(pager);
		System.out.println(pr.getRowCount());
		System.out.println(pr.getResultSet().size());

		model.addAttribute("movie", name);
		return "home/list";
	}

}
